Socket
Socket
Sign inDemoInstall

@paprika/popover

Package Overview
Dependencies
10
Maintainers
5
Versions
128
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @paprika/popover

Popover component renders an overlay of content anchored to a trigger button (or specific positioning element). It can be triggered by click (or keypress), by hover (or keyboard focus – as a tooltip), or programatically


Version published
Weekly downloads
4.9K
decreased by-0.69%
Maintainers
5
Created
Weekly downloads
 

Readme

Source

@paprika/popover - 0.3.36

Description

Popover component renders an overlay of content anchored to a trigger button (or specific positioning element). It can be triggered by click (or keypress), by hover (or keyboard focus – as a tooltip), or programatically

Installation

yarn add @paprika/popover

or with npm:

npm install @paprika/popover

Props

Popover

PropTyperequireddefaultDescription
align[ Popover.types.align.TOP, Popover.types.align.RIGHT, Popover.types.align.BOTTOM, Popover.types.align.LEFT]falsePopover.types.align.BOTTOMWhere the popover content is positioned relative to the trigger or getPositioningElement.
childrennodetrue-Content of the popover
isDarkboolfalsefalseDisplays as a "tooltip" style with white text on black background.
isEagerboolfalsefalseActivated by mouseOver / focus instead of onClick.
isOpenboolfalsenullHow "controlled" popovers are shown / hidden.
isPortalboolfalsetrueThis renders the popover inline in the DOM and not in a react portal. WARNING: will have side effects with paprika side panels and modals, use with caution.
defaultIsOpenboolfalsenullHow "uncontrolled" popovers can be rendered open by default.
edge[ Popover.types.align.LEFT, Popover.types.align.RIGHT, null]falsenullWhere the edge of the popover content is based on the trigger or getPositioningElement
maxWidth[string,number]false320Maximum width of popover content. Using a number is recommended and implies px units.
minWidth[string,number]false0Minimumn width of popover content. Using a number is recommended and implies px units.
onClosefuncfalsenullCallback to fire when user closes popover.
offsetnumberfalseparseInt(tokens.spaceLg, 10)Distance, in px, between popover content edge and trigger / getPositioningElement.
getPositioningElementfuncfalsenullFunction that provides DOM element to use as target for positioning the popover.
getScrollContainerfuncfalsenullFunction that provides the scrolling DOM element that contains the popover.
shouldKeepFocusboolfalsefalseIf focus will stay at the trigger when showing popover. Popover can still be closed when clicking outside or pressing escape key.
zIndexnumberfalsezValue(1)Number setting the z-index for the popover content / tip.

Popover.Trigger

PropTyperequireddefaultDescription
a11yTextstringfalsenullDescriptive a11y text for assistive technologies for the trigger.
children[func,node]true-

Popover.Content

PropTyperequireddefaultDescription
childrennodefalsenull
onBlurfuncfalse() => {}Callback to indicate the element loses focus

Popover.Card

PropTyperequireddefaultDescription
childrennodetrue-

Popover.Tip

PropTyperequireddefaultDescription
zIndexnumberfalsenullNumber setting the z-index

Usage

The <Popover> can be used as a controlled or uncontrolled component. If controlled, the isOpen and onClose props must be utilized.

Tooltip style

The <Popover> can be used as a tooltip by making it open "eagerly" on hover or keyboard focus via the isEager prop. Typically a very short tooltip is also designed with white text on a black background, achieved with the isDark prop.

Popover.Trigger

With an uncontrolled <Popover>, it may be convenient to use the <Popover.Trigger> to wrap the element the user will interact with to display the popover because this results in a <RawButton> being wrapped around that UI element, with all of the handlers it requires already hooked up.

For a controlled <Popover>, or the case where the <Popover.Trigger> child element is a <Button>, it is necessary to use a render function for the children of the <Popover.Trigger>, which will be provided with a generic handler argument.

It may not be necessary to use a <Popover.Trigger> element at all if the <Popover> is controlled. Then its children (excluding <Popover.Content> and <Popover.Tip>) will by default be used as the positioning element (see Basic controlled example below).

Popover.Content

Content for the <Popover> is also included as children, wrapped by the <Popover.Content>. For a "card" style, the <Popover.Card> is a convenient helper.

Popover.Tip

To include an arrow that points to the trigger element, the <Popover.Tip> can be included as a sibling element of the <Popover.Content> (include it after the Content to avoid an explicit zIndex prop on the Tip).

Basic uncontrolled example

import Popover from "@paprika/popover";

<Popover>
  <Popover.Trigger>
    <Icon />
  </Popover.Trigger>
  <Popover.Content>
    <Popover.Card>Lorem hipsum kombucha leggings vinyl.</Popover.Card>
  </Popover.Content>
  <Popover.Tip />
</Popover>;

Basic controlled example

import Popover from "@paprika/popover";

const [isOpen, setOpen] = React.useState(false);

<Popover isOpen={isOpen} onClose={() => { setOpen(false) }>
  <Button onClick={() => { setOpen(prevOpen => !prevOpen) }}>
    Open Popover
  </Button>
  <Popover.Content>
    <Popover.Card>
      Lorem hipsum kombucha leggings vinyl.
    </Popover.Card>
  </Popover.Content>
  <Popover.Tip />
</Popover>
  • Storybook showcase
  • Github source code
  • Github create issue
  • ChangeLog

FAQs

Last updated on 09 Nov 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc